package com.decent.manager.system.dao.provider;

import cn.hutool.core.text.CharSequenceUtil;
import com.decent.manager.system.dto.SystemRoleDTO;

import java.util.Map;

/**
 * 系统角色sql管理
 *
 * @author wangyan
 **/
public class SystemRoleDaoProvider {
    /**
     * 修改角色
     *
     * @param params 修改条件
     * @return sql
     */
    @SuppressWarnings("unused")
    public String updateRole(Map<String, SystemRoleDTO> params) {
        StringBuilder sql = new StringBuilder(127);
        sql.append("update system_role set update_time = now(), last_modifier = #{role.lastModifier} ");
        SystemRoleDTO role = params.get("role");
        if (CharSequenceUtil.isNotBlank(role.getRoleName())) {
            sql.append(", role_name = #{role.roleName}, role_code = #{role.roleCode} ");
        }
        if (role.getRoleSort() != null) {
            sql.append(", role_sort = #{role.roleSort} ");
        }
        if (CharSequenceUtil.isNotBlank(role.getRemark())) {
            sql.append(", remark = #{role.remark} ");
        }
        if (role.getRoleStatus() != null) {
            sql.append(", role_status = #{role.roleStatus} ");
        }
        sql.append(" where id = #{role.id}");
        return sql.toString();
    }
}
